home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume23 / flex2.3 / part05 < prev    next >
Encoding:
Internet Message Format  |  1990-10-10  |  50.9 KB

  1. Subject:  v23i041:  Flex, a fast lex replacement, Part05/10
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: ec57c692 265e2299 7f1a36e3 d2f59402
  5.  
  6. Submitted-by: Vern Paxson <vern@cs.cornell.edu>
  7. Posting-number: Volume 23, Issue 41
  8. Archive-name: flex2.3/part05
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # Contents:  flexdef.h main.c
  17. # Wrapped by rsalz@litchi.bbn.com on Wed Oct 10 13:24:01 1990
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. echo If this archive is complete, you will see the following message:
  20. echo '          "shar: End of archive 5 (of 10)."'
  21. if test -f 'flexdef.h' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'flexdef.h'\"
  23. else
  24.   echo shar: Extracting \"'flexdef.h'\" \(29063 characters\)
  25.   sed "s/^X//" >'flexdef.h' <<'END_OF_FILE'
  26. X/* flexdef - definitions file for flex */
  27. X
  28. X/*-
  29. X * Copyright (c) 1990 The Regents of the University of California.
  30. X * All rights reserved.
  31. X *
  32. X * This code is derived from software contributed to Berkeley by
  33. X * Vern Paxson.
  34. X * 
  35. X * The United States Government has rights in this work pursuant
  36. X * to contract no. DE-AC03-76SF00098 between the United States
  37. X * Department of Energy and the University of California.
  38. X *
  39. X * Redistribution and use in source and binary forms are permitted provided
  40. X * that: (1) source distributions retain this entire copyright notice and
  41. X * comment, and (2) distributions including binaries display the following
  42. X * acknowledgement:  ``This product includes software developed by the
  43. X * University of California, Berkeley and its contributors'' in the
  44. X * documentation or other materials provided with the distribution and in
  45. X * all advertising materials mentioning features or use of this software.
  46. X * Neither the name of the University nor the names of its contributors may
  47. X * be used to endorse or promote products derived from this software without
  48. X * specific prior written permission.
  49. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  50. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  51. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  52. X */
  53. X
  54. X/* @(#) $Header: /usr/fsys/odin/a/vern/flex/RCS/flexdef.h,v 2.10 90/08/03 14:09:52 vern Exp $ (LBL) */
  55. X
  56. X#ifndef FILE
  57. X#include <stdio.h>
  58. X#endif
  59. X
  60. X/* always be prepared to generate an 8-bit scanner */
  61. X#define FLEX_8_BIT_CHARS
  62. X
  63. X#ifdef FLEX_8_BIT_CHARS
  64. X#define CSIZE 256
  65. X#define Char unsigned char
  66. X#else
  67. X#define Char char
  68. X#define CSIZE 128
  69. X#endif
  70. X
  71. X/* size of input alphabet - should be size of ASCII set */
  72. X#ifndef DEFAULT_CSIZE
  73. X#define DEFAULT_CSIZE 128
  74. X#endif
  75. X
  76. X#ifndef PROTO
  77. X#ifdef __STDC__
  78. X#define PROTO(proto) proto
  79. X#else
  80. X#define PROTO(proto) ()
  81. X#endif
  82. X#endif
  83. X
  84. X
  85. X#ifdef USG
  86. X#define SYS_V
  87. X#endif
  88. X
  89. X#ifdef SYS_V
  90. X#include <string.h>
  91. X#else
  92. X
  93. X#include <strings.h>
  94. X#ifdef lint
  95. Xchar *sprintf(); /* keep lint happy */
  96. X#endif
  97. X#ifdef SCO_UNIX
  98. Xvoid *memset();
  99. X#else
  100. Xchar *memset();
  101. X#endif
  102. X#endif
  103. X
  104. X#ifdef AMIGA
  105. X#define bzero(s, n) setmem((char *)(s), n, '\0')
  106. X#ifndef abs
  107. X#define abs(x) ((x) < 0 ? -(x) : (x))
  108. X#endif
  109. X#else
  110. X#define bzero(s, n) (void) memset((char *)(s), '\0', n)
  111. X#endif
  112. X
  113. X#ifdef VMS
  114. X#define unlink delete
  115. X#define SHORT_FILE_NAMES
  116. X#endif
  117. X
  118. X#ifdef __STDC__
  119. X
  120. X#ifdef __GNUC__
  121. X#include <stddef.h>
  122. Xvoid *malloc( size_t );
  123. Xvoid free( void* );
  124. X#else
  125. X#include <stdlib.h>
  126. X#endif
  127. X
  128. X#else    /* ! __STDC__ */
  129. Xchar *malloc(), *realloc();
  130. X#endif
  131. X
  132. X
  133. X/* maximum line length we'll have to deal with */
  134. X#define MAXLINE BUFSIZ
  135. X
  136. X/* maximum size of file name */
  137. X#define FILENAMESIZE 1024
  138. X
  139. X#ifndef min
  140. X#define min(x,y) ((x) < (y) ? (x) : (y))
  141. X#endif
  142. X#ifndef max
  143. X#define max(x,y) ((x) > (y) ? (x) : (y))
  144. X#endif
  145. X
  146. X#ifdef MS_DOS
  147. X#ifndef abs
  148. X#define abs(x) ((x) < 0 ? -(x) : (x))
  149. X#endif
  150. X#define SHORT_FILE_NAMES
  151. X#endif
  152. X
  153. X#define true 1
  154. X#define false 0
  155. X
  156. X
  157. X#ifndef DEFAULT_SKELETON_FILE
  158. X#define DEFAULT_SKELETON_FILE "flex.skel"
  159. X#endif
  160. X
  161. X/* special chk[] values marking the slots taking by end-of-buffer and action
  162. X * numbers
  163. X */
  164. X#define EOB_POSITION -1
  165. X#define ACTION_POSITION -2
  166. X
  167. X/* number of data items per line for -f output */
  168. X#define NUMDATAITEMS 10
  169. X
  170. X/* number of lines of data in -f output before inserting a blank line for
  171. X * readability.
  172. X */
  173. X#define NUMDATALINES 10
  174. X
  175. X/* transition_struct_out() definitions */
  176. X#define TRANS_STRUCT_PRINT_LENGTH 15
  177. X
  178. X/* returns true if an nfa state has an epsilon out-transition slot
  179. X * that can be used.  This definition is currently not used.
  180. X */
  181. X#define FREE_EPSILON(state) \
  182. X    (transchar[state] == SYM_EPSILON && \
  183. X     trans2[state] == NO_TRANSITION && \
  184. X     finalst[state] != state)
  185. X
  186. X/* returns true if an nfa state has an epsilon out-transition character
  187. X * and both slots are free
  188. X */
  189. X#define SUPER_FREE_EPSILON(state) \
  190. X    (transchar[state] == SYM_EPSILON && \
  191. X     trans1[state] == NO_TRANSITION) \
  192. X
  193. X/* maximum number of NFA states that can comprise a DFA state.  It's real
  194. X * big because if there's a lot of rules, the initial state will have a
  195. X * huge epsilon closure.
  196. X */
  197. X#define INITIAL_MAX_DFA_SIZE 750
  198. X#define MAX_DFA_SIZE_INCREMENT 750
  199. X
  200. X
  201. X/* a note on the following masks.  They are used to mark accepting numbers
  202. X * as being special.  As such, they implicitly limit the number of accepting
  203. X * numbers (i.e., rules) because if there are too many rules the rule numbers
  204. X * will overload the mask bits.  Fortunately, this limit is \large/ (0x2000 ==
  205. X * 8192) so unlikely to actually cause any problems.  A check is made in
  206. X * new_rule() to ensure that this limit is not reached.
  207. X */
  208. X
  209. X/* mask to mark a trailing context accepting number */
  210. X#define YY_TRAILING_MASK 0x2000
  211. X
  212. X/* mask to mark the accepting number of the "head" of a trailing context rule */
  213. X#define YY_TRAILING_HEAD_MASK 0x4000
  214. X
  215. X/* maximum number of rules, as outlined in the above note */
  216. X#define MAX_RULE (YY_TRAILING_MASK - 1)
  217. X
  218. X
  219. X/* NIL must be 0.  If not, its special meaning when making equivalence classes
  220. X * (it marks the representative of a given e.c.) will be unidentifiable
  221. X */
  222. X#define NIL 0
  223. X
  224. X#define JAM -1    /* to mark a missing DFA transition */
  225. X#define NO_TRANSITION NIL
  226. X#define UNIQUE -1    /* marks a symbol as an e.c. representative */
  227. X#define INFINITY -1    /* for x{5,} constructions */
  228. X
  229. X#define INITIAL_MAX_CCLS 100    /* max number of unique character classes */
  230. X#define MAX_CCLS_INCREMENT 100
  231. X
  232. X/* size of table holding members of character classes */
  233. X#define INITIAL_MAX_CCL_TBL_SIZE 500
  234. X#define MAX_CCL_TBL_SIZE_INCREMENT 250
  235. X
  236. X#define INITIAL_MAX_RULES 100    /* default maximum number of rules */
  237. X#define MAX_RULES_INCREMENT 100
  238. X
  239. X#define INITIAL_MNS 2000    /* default maximum number of nfa states */
  240. X#define MNS_INCREMENT 1000    /* amount to bump above by if it's not enough */
  241. X
  242. X#define INITIAL_MAX_DFAS 1000    /* default maximum number of dfa states */
  243. X#define MAX_DFAS_INCREMENT 1000
  244. X
  245. X#define JAMSTATE -32766    /* marks a reference to the state that always jams */
  246. X
  247. X/* enough so that if it's subtracted from an NFA state number, the result
  248. X * is guaranteed to be negative
  249. X */
  250. X#define MARKER_DIFFERENCE 32000
  251. X#define MAXIMUM_MNS 31999
  252. X
  253. X/* maximum number of nxt/chk pairs for non-templates */
  254. X#define INITIAL_MAX_XPAIRS 2000
  255. X#define MAX_XPAIRS_INCREMENT 2000
  256. X
  257. X/* maximum number of nxt/chk pairs needed for templates */
  258. X#define INITIAL_MAX_TEMPLATE_XPAIRS 2500
  259. X#define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
  260. X
  261. X#define SYM_EPSILON (CSIZE + 1)    /* to mark transitions on the symbol epsilon */
  262. X
  263. X#define INITIAL_MAX_SCS 40    /* maximum number of start conditions */
  264. X#define MAX_SCS_INCREMENT 40    /* amount to bump by if it's not enough */
  265. X
  266. X#define ONE_STACK_SIZE 500    /* stack of states with only one out-transition */
  267. X#define SAME_TRANS -1    /* transition is the same as "default" entry for state */
  268. X
  269. X/* the following percentages are used to tune table compression:
  270. X
  271. X * the percentage the number of out-transitions a state must be of the
  272. X * number of equivalence classes in order to be considered for table
  273. X * compaction by using protos
  274. X */
  275. X#define PROTO_SIZE_PERCENTAGE 15
  276. X
  277. X/* the percentage the number of homogeneous out-transitions of a state
  278. X * must be of the number of total out-transitions of the state in order
  279. X * that the state's transition table is first compared with a potential 
  280. X * template of the most common out-transition instead of with the first
  281. X * proto in the proto queue
  282. X */
  283. X#define CHECK_COM_PERCENTAGE 50
  284. X
  285. X/* the percentage the number of differences between a state's transition
  286. X * table and the proto it was first compared with must be of the total
  287. X * number of out-transitions of the state in order to keep the first
  288. X * proto as a good match and not search any further
  289. X */
  290. X#define FIRST_MATCH_DIFF_PERCENTAGE 10
  291. X
  292. X/* the percentage the number of differences between a state's transition
  293. X * table and the most similar proto must be of the state's total number
  294. X * of out-transitions to use the proto as an acceptable close match
  295. X */
  296. X#define ACCEPTABLE_DIFF_PERCENTAGE 50
  297. X
  298. X/* the percentage the number of homogeneous out-transitions of a state
  299. X * must be of the number of total out-transitions of the state in order
  300. X * to consider making a template from the state
  301. X */
  302. X#define TEMPLATE_SAME_PERCENTAGE 60
  303. X
  304. X/* the percentage the number of differences between a state's transition
  305. X * table and the most similar proto must be of the state's total number
  306. X * of out-transitions to create a new proto from the state
  307. X */
  308. X#define NEW_PROTO_DIFF_PERCENTAGE 20
  309. X
  310. X/* the percentage the total number of out-transitions of a state must be
  311. X * of the number of equivalence classes in order to consider trying to
  312. X * fit the transition table into "holes" inside the nxt/chk table.
  313. X */
  314. X#define INTERIOR_FIT_PERCENTAGE 15
  315. X
  316. X/* size of region set aside to cache the complete transition table of
  317. X * protos on the proto queue to enable quick comparisons
  318. X */
  319. X#define PROT_SAVE_SIZE 2000
  320. X
  321. X#define MSP 50    /* maximum number of saved protos (protos on the proto queue) */
  322. X
  323. X/* maximum number of out-transitions a state can have that we'll rummage
  324. X * around through the interior of the internal fast table looking for a
  325. X * spot for it
  326. X */
  327. X#define MAX_XTIONS_FULL_INTERIOR_FIT 4
  328. X
  329. X/* maximum number of rules which will be reported as being associated
  330. X * with a DFA state
  331. X */
  332. X#define MAX_ASSOC_RULES 100
  333. X
  334. X/* number that, if used to subscript an array, has a good chance of producing
  335. X * an error; should be small enough to fit into a short
  336. X */
  337. X#define BAD_SUBSCRIPT -32767
  338. X
  339. X/* absolute value of largest number that can be stored in a short, with a
  340. X * bit of slop thrown in for general paranoia.
  341. X */
  342. X#define MAX_SHORT 32766
  343. X
  344. X
  345. X/* Declarations for global variables. */
  346. X
  347. X/* variables for symbol tables:
  348. X * sctbl - start-condition symbol table
  349. X * ndtbl - name-definition symbol table
  350. X * ccltab - character class text symbol table
  351. X */
  352. X
  353. Xstruct hash_entry
  354. X    {
  355. X    struct hash_entry *prev, *next;
  356. X    char *name;
  357. X    char *str_val;
  358. X    int int_val;
  359. X    } ;
  360. X
  361. Xtypedef struct hash_entry *hash_table[];
  362. X
  363. X#define NAME_TABLE_HASH_SIZE 101
  364. X#define START_COND_HASH_SIZE 101
  365. X#define CCL_HASH_SIZE 101
  366. X
  367. Xextern struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE]; 
  368. Xextern struct hash_entry *sctbl[START_COND_HASH_SIZE];
  369. Xextern struct hash_entry *ccltab[CCL_HASH_SIZE];
  370. X
  371. X
  372. X/* variables for flags:
  373. X * printstats - if true (-v), dump statistics
  374. X * syntaxerror - true if a syntax error has been found
  375. X * eofseen - true if we've seen an eof in the input file
  376. X * ddebug - if true (-d), make a "debug" scanner
  377. X * trace - if true (-T), trace processing
  378. X * spprdflt - if true (-s), suppress the default rule
  379. X * interactive - if true (-I), generate an interactive scanner
  380. X * caseins - if true (-i), generate a case-insensitive scanner
  381. X * useecs - if true (-Ce flag), use equivalence classes
  382. X * fulltbl - if true (-Cf flag), don't compress the DFA state table
  383. X * usemecs - if true (-Cm flag), use meta-equivalence classes
  384. X * fullspd - if true (-F flag), use Jacobson method of table representation
  385. X * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
  386. X * performance_report - if true (i.e., -p flag), generate a report relating
  387. X *   to scanner performance
  388. X * backtrack_report - if true (i.e., -b flag), generate "lex.backtrack" file
  389. X *   listing backtracking states
  390. X * csize - size of character set for the scanner we're generating;
  391. X *   128 for 7-bit chars and 256 for 8-bit
  392. X * yymore_used - if true, yymore() is used in input rules
  393. X * reject - if true, generate backtracking tables for REJECT macro
  394. X * real_reject - if true, scanner really uses REJECT (as opposed to just
  395. X *   having "reject" set for variable trailing context)
  396. X * continued_action - true if this rule's action is to "fall through" to
  397. X *   the next rule's action (i.e., the '|' action)
  398. X * yymore_really_used - has a REALLY_xxx value indicating whether a
  399. X *   %used or %notused was used with yymore()
  400. X * reject_really_used - same for REJECT
  401. X */
  402. X
  403. Xextern int printstats, syntaxerror, eofseen, ddebug, trace, spprdflt;
  404. Xextern int interactive, caseins, useecs, fulltbl, usemecs;
  405. Xextern int fullspd, gen_line_dirs, performance_report, backtrack_report, csize;
  406. Xextern int yymore_used, reject, real_reject, continued_action;
  407. X
  408. X#define REALLY_NOT_DETERMINED 0
  409. X#define REALLY_USED 1
  410. X#define REALLY_NOT_USED 2
  411. Xextern int yymore_really_used, reject_really_used;
  412. X
  413. X
  414. X/* variables used in the flex input routines:
  415. X * datapos - characters on current output line
  416. X * dataline - number of contiguous lines of data in current data
  417. X *    statement.  Used to generate readable -f output
  418. X * linenum - current input line number
  419. X * skelfile - the skeleton file
  420. X * yyin - input file
  421. X * temp_action_file - temporary file to hold actions
  422. X * backtrack_file - file to summarize backtracking states to
  423. X * infilename - name of input file
  424. X * action_file_name - name of the temporary file
  425. X * input_files - array holding names of input files
  426. X * num_input_files - size of input_files array
  427. X * program_name - name with which program was invoked 
  428. X */
  429. X
  430. Xextern int datapos, dataline, linenum;
  431. Xextern FILE *skelfile, *yyin, *temp_action_file, *backtrack_file;
  432. Xextern char *infilename;
  433. Xextern char *action_file_name;
  434. Xextern char **input_files;
  435. Xextern int num_input_files;
  436. Xextern char *program_name;
  437. X
  438. X
  439. X/* variables for stack of states having only one out-transition:
  440. X * onestate - state number
  441. X * onesym - transition symbol
  442. X * onenext - target state
  443. X * onedef - default base entry
  444. X * onesp - stack pointer
  445. X */
  446. X
  447. Xextern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
  448. Xextern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
  449. X
  450. X
  451. X/* variables for nfa machine data:
  452. X * current_mns - current maximum on number of NFA states
  453. X * num_rules - number of the last accepting state; also is number of
  454. X *             rules created so far
  455. X * current_max_rules - current maximum number of rules
  456. X * lastnfa - last nfa state number created
  457. X * firstst - physically the first state of a fragment
  458. X * lastst - last physical state of fragment
  459. X * finalst - last logical state of fragment
  460. X * transchar - transition character
  461. X * trans1 - transition state
  462. X * trans2 - 2nd transition state for epsilons
  463. X * accptnum - accepting number
  464. X * assoc_rule - rule associated with this NFA state (or 0 if none)
  465. X * state_type - a STATE_xxx type identifying whether the state is part
  466. X *              of a normal rule, the leading state in a trailing context
  467. X *              rule (i.e., the state which marks the transition from
  468. X *              recognizing the text-to-be-matched to the beginning of
  469. X *              the trailing context), or a subsequent state in a trailing
  470. X *              context rule
  471. X * rule_type - a RULE_xxx type identifying whether this a a ho-hum
  472. X *             normal rule or one which has variable head & trailing
  473. X *             context
  474. X * rule_linenum - line number associated with rule
  475. X */
  476. X
  477. Xextern int current_mns, num_rules, current_max_rules, lastnfa;
  478. Xextern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
  479. Xextern int *accptnum, *assoc_rule, *state_type, *rule_type, *rule_linenum;
  480. X
  481. X/* different types of states; values are useful as masks, as well, for
  482. X * routines like check_trailing_context()
  483. X */
  484. X#define STATE_NORMAL 0x1
  485. X#define STATE_TRAILING_CONTEXT 0x2
  486. X
  487. X/* global holding current type of state we're making */
  488. X
  489. Xextern int current_state_type;
  490. X
  491. X/* different types of rules */
  492. X#define RULE_NORMAL 0
  493. X#define RULE_VARIABLE 1
  494. X
  495. X/* true if the input rules include a rule with both variable-length head
  496. X * and trailing context, false otherwise
  497. X */
  498. Xextern int variable_trailing_context_rules;
  499. X
  500. X
  501. X/* variables for protos:
  502. X * numtemps - number of templates created
  503. X * numprots - number of protos created
  504. X * protprev - backlink to a more-recently used proto
  505. X * protnext - forward link to a less-recently used proto
  506. X * prottbl - base/def table entry for proto
  507. X * protcomst - common state of proto
  508. X * firstprot - number of the most recently used proto
  509. X * lastprot - number of the least recently used proto
  510. X * protsave contains the entire state array for protos
  511. X */
  512. X
  513. Xextern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
  514. Xextern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
  515. X
  516. X
  517. X/* variables for managing equivalence classes:
  518. X * numecs - number of equivalence classes
  519. X * nextecm - forward link of Equivalence Class members
  520. X * ecgroup - class number or backward link of EC members
  521. X * nummecs - number of meta-equivalence classes (used to compress
  522. X *   templates)
  523. X * tecfwd - forward link of meta-equivalence classes members
  524. X * tecbck - backward link of MEC's
  525. X * xlation - maps character codes to their translations, or nil if no %t table
  526. X * num_xlations - number of different xlation values
  527. X */
  528. X
  529. X/* reserve enough room in the equivalence class arrays so that we
  530. X * can use the CSIZE'th element to hold equivalence class information
  531. X * for the NUL character.  Later we'll move this information into
  532. X * the 0th element.
  533. X */
  534. Xextern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
  535. X
  536. X/* meta-equivalence classes are indexed starting at 1, so it's possible
  537. X * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
  538. X * slots total (since the arrays are 0-based).  nextecm[] and ecgroup[]
  539. X * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
  540. X */
  541. Xextern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
  542. X
  543. Xextern int *xlation;
  544. Xextern int num_xlations;
  545. X
  546. X
  547. X/* variables for start conditions:
  548. X * lastsc - last start condition created
  549. X * current_max_scs - current limit on number of start conditions
  550. X * scset - set of rules active in start condition
  551. X * scbol - set of rules active only at the beginning of line in a s.c.
  552. X * scxclu - true if start condition is exclusive
  553. X * sceof - true if start condition has EOF rule
  554. X * scname - start condition name
  555. X * actvsc - stack of active start conditions for the current rule
  556. X */
  557. X
  558. Xextern int lastsc, current_max_scs, *scset, *scbol, *scxclu, *sceof, *actvsc;
  559. Xextern char **scname;
  560. X
  561. X
  562. X/* variables for dfa machine data:
  563. X * current_max_dfa_size - current maximum number of NFA states in DFA
  564. X * current_max_xpairs - current maximum number of non-template xtion pairs
  565. X * current_max_template_xpairs - current maximum number of template pairs
  566. X * current_max_dfas - current maximum number DFA states
  567. X * lastdfa - last dfa state number created
  568. X * nxt - state to enter upon reading character
  569. X * chk - check value to see if "nxt" applies
  570. X * tnxt - internal nxt table for templates
  571. X * base - offset into "nxt" for given state
  572. X * def - where to go if "chk" disallows "nxt" entry
  573. X * nultrans - NUL transition for each state
  574. X * NUL_ec - equivalence class of the NUL character
  575. X * tblend - last "nxt/chk" table entry being used
  576. X * firstfree - first empty entry in "nxt/chk" table
  577. X * dss - nfa state set for each dfa
  578. X * dfasiz - size of nfa state set for each dfa
  579. X * dfaacc - accepting set for each dfa state (or accepting number, if
  580. X *    -r is not given)
  581. X * accsiz - size of accepting set for each dfa state
  582. X * dhash - dfa state hash value
  583. X * numas - number of DFA accepting states created; note that this
  584. X *    is not necessarily the same value as num_rules, which is the analogous
  585. X *    value for the NFA
  586. X * numsnpairs - number of state/nextstate transition pairs
  587. X * jambase - position in base/def where the default jam table starts
  588. X * jamstate - state number corresponding to "jam" state
  589. X * end_of_buffer_state - end-of-buffer dfa state number
  590. X */
  591. X
  592. Xextern int current_max_dfa_size, current_max_xpairs;
  593. Xextern int current_max_template_xpairs, current_max_dfas;
  594. Xextern int lastdfa, lasttemp, *nxt, *chk, *tnxt;
  595. Xextern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
  596. Xextern union dfaacc_union
  597. X    {
  598. X    int *dfaacc_set;
  599. X    int dfaacc_state;
  600. X    } *dfaacc;
  601. Xextern int *accsiz, *dhash, numas;
  602. Xextern int numsnpairs, jambase, jamstate;
  603. Xextern int end_of_buffer_state;
  604. X
  605. X/* variables for ccl information:
  606. X * lastccl - ccl index of the last created ccl
  607. X * current_maxccls - current limit on the maximum number of unique ccl's
  608. X * cclmap - maps a ccl index to its set pointer
  609. X * ccllen - gives the length of a ccl
  610. X * cclng - true for a given ccl if the ccl is negated
  611. X * cclreuse - counts how many times a ccl is re-used
  612. X * current_max_ccl_tbl_size - current limit on number of characters needed
  613. X *    to represent the unique ccl's
  614. X * ccltbl - holds the characters in each ccl - indexed by cclmap
  615. X */
  616. X
  617. Xextern int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse;
  618. Xextern int current_max_ccl_tbl_size;
  619. Xextern Char *ccltbl;
  620. X
  621. X
  622. X/* variables for miscellaneous information:
  623. X * starttime - real-time when we started
  624. X * endtime - real-time when we ended
  625. X * nmstr - last NAME scanned by the scanner
  626. X * sectnum - section number currently being parsed
  627. X * nummt - number of empty nxt/chk table entries
  628. X * hshcol - number of hash collisions detected by snstods
  629. X * dfaeql - number of times a newly created dfa was equal to an old one
  630. X * numeps - number of epsilon NFA states created
  631. X * eps2 - number of epsilon states which have 2 out-transitions
  632. X * num_reallocs - number of times it was necessary to realloc() a group
  633. X *          of arrays
  634. X * tmpuses - number of DFA states that chain to templates
  635. X * totnst - total number of NFA states used to make DFA states
  636. X * peakpairs - peak number of transition pairs we had to store internally
  637. X * numuniq - number of unique transitions
  638. X * numdup - number of duplicate transitions
  639. X * hshsave - number of hash collisions saved by checking number of states
  640. X * num_backtracking - number of DFA states requiring back-tracking
  641. X * bol_needed - whether scanner needs beginning-of-line recognition
  642. X */
  643. X
  644. Xextern char *starttime, *endtime, nmstr[MAXLINE];
  645. Xextern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
  646. Xextern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
  647. Xextern int num_backtracking, bol_needed;
  648. X
  649. Xvoid *allocate_array(), *reallocate_array();
  650. X
  651. X#define allocate_integer_array(size) \
  652. X    (int *) allocate_array( size, sizeof( int ) )
  653. X
  654. X#define reallocate_integer_array(array,size) \
  655. X    (int *) reallocate_array( (void *) array, size, sizeof( int ) )
  656. X
  657. X#define allocate_int_ptr_array(size) \
  658. X    (int **) allocate_array( size, sizeof( int * ) )
  659. X
  660. X#define allocate_char_ptr_array(size) \
  661. X    (char **) allocate_array( size, sizeof( char * ) )
  662. X
  663. X#define allocate_dfaacc_union(size) \
  664. X    (union dfaacc_union *) \
  665. X        allocate_array( size, sizeof( union dfaacc_union ) )
  666. X
  667. X#define reallocate_int_ptr_array(array,size) \
  668. X    (int **) reallocate_array( (void *) array, size, sizeof( int * ) )
  669. X
  670. X#define reallocate_char_ptr_array(array,size) \
  671. X    (char **) reallocate_array( (void *) array, size, sizeof( char * ) )
  672. X
  673. X#define reallocate_dfaacc_union(array, size) \
  674. X    (union dfaacc_union *) \
  675. X    reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) )
  676. X
  677. X#define allocate_character_array(size) \
  678. X    (Char *) allocate_array( size, sizeof( Char ) )
  679. X
  680. X#define reallocate_character_array(array,size) \
  681. X    (Char *) reallocate_array( (void *) array, size, sizeof( Char ) )
  682. X
  683. X
  684. X/* used to communicate between scanner and parser.  The type should really
  685. X * be YYSTYPE, but we can't easily get our hands on it.
  686. X */
  687. Xextern int yylval;
  688. X
  689. X
  690. X/* external functions that are cross-referenced among the flex source files */
  691. X
  692. X
  693. X/* from file ccl.c */
  694. X
  695. Xextern void ccladd PROTO((int, int));    /* Add a single character to a ccl */
  696. Xextern int cclinit PROTO(());    /* make an empty ccl */
  697. Xextern void cclnegate PROTO((int));    /* negate a ccl */
  698. X
  699. X/* list the members of a set of characters in CCL form */
  700. Xextern void list_character_set PROTO((FILE*, int[]));
  701. X
  702. X
  703. X/* from file dfa.c */
  704. X
  705. X/* increase the maximum number of dfas */
  706. Xextern void increase_max_dfas PROTO(());
  707. X
  708. Xextern void ntod PROTO(());    /* convert a ndfa to a dfa */
  709. X
  710. X
  711. X/* from file ecs.c */
  712. X
  713. X/* convert character classes to set of equivalence classes */
  714. Xextern void ccl2ecl PROTO(());
  715. X
  716. X/* associate equivalence class numbers with class members */
  717. Xextern int cre8ecs PROTO((int[], int[], int));
  718. X
  719. X/* associate equivalence class numbers using %t table */
  720. Xextern int ecs_from_xlation PROTO((int[]));
  721. X
  722. X/* update equivalence classes based on character class transitions */
  723. Xextern void mkeccl PROTO((Char[], int, int[], int[], int, int));
  724. X
  725. X/* create equivalence class for single character */
  726. Xextern void mkechar PROTO((int, int[], int[]));
  727. X
  728. X
  729. X/* from file gen.c */
  730. X
  731. Xextern void make_tables PROTO(());    /* generate transition tables */
  732. X
  733. X
  734. X/* from file main.c */
  735. X
  736. Xextern void flexend PROTO((int));
  737. X
  738. X
  739. X/* from file misc.c */
  740. X
  741. X/* write out the actions from the temporary file to lex.yy.c */
  742. Xextern void action_out PROTO(());
  743. X
  744. X/* true if a string is all lower case */
  745. Xextern int all_lower PROTO((register Char *));
  746. X
  747. X/* true if a string is all upper case */
  748. Xextern int all_upper PROTO((register Char *));
  749. X
  750. X/* bubble sort an integer array */
  751. Xextern void bubble PROTO((int [], int));
  752. X
  753. X/* shell sort a character array */
  754. Xextern void cshell PROTO((Char [], int, int));
  755. X
  756. Xextern void dataend PROTO(());    /* finish up a block of data declarations */
  757. X
  758. X/* report an error message and terminate */
  759. Xextern void flexerror PROTO((char[]));
  760. X
  761. X/* report a fatal error message and terminate */
  762. Xextern void flexfatal PROTO((char[]));
  763. X
  764. X/* report an error message formatted with one integer argument */
  765. Xextern void lerrif PROTO((char[], int));
  766. X
  767. X/* report an error message formatted with one string argument */
  768. Xextern void lerrsf PROTO((char[], char[]));
  769. X
  770. X/* spit out a "# line" statement */
  771. Xextern void line_directive_out PROTO((FILE*));
  772. X
  773. X/* generate a data statment for a two-dimensional array */
  774. Xextern void mk2data PROTO((int));
  775. X
  776. Xextern void mkdata PROTO((int));    /* generate a data statement */
  777. X
  778. X/* return the integer represented by a string of digits */
  779. Xextern int myctoi PROTO((Char []));
  780. X
  781. X/* write out one section of the skeleton file */
  782. Xextern void skelout PROTO(());
  783. X
  784. X/* output a yy_trans_info structure */
  785. Xextern void transition_struct_out PROTO((int, int));
  786. X
  787. X
  788. X/* from file nfa.c */
  789. X
  790. X/* add an accepting state to a machine */
  791. Xextern void add_accept PROTO((int, int));
  792. X
  793. X/* make a given number of copies of a singleton machine */
  794. Xextern int copysingl PROTO((int, int));
  795. X
  796. X/* debugging routine to write out an nfa */
  797. Xextern void dumpnfa PROTO((int));
  798. X
  799. X/* finish up the processing for a rule */
  800. Xextern void finish_rule PROTO((int, int, int, int));
  801. X
  802. X/* connect two machines together */
  803. Xextern int link_machines PROTO((int, int));
  804. X
  805. X/* mark each "beginning" state in a machine as being a "normal" (i.e.,
  806. X * not trailing context associated) state
  807. X */
  808. Xextern void mark_beginning_as_normal PROTO((register int));
  809. X
  810. X/* make a machine that branches to two machines */
  811. Xextern int mkbranch PROTO((int, int));
  812. X
  813. Xextern int mkclos PROTO((int));    /* convert a machine into a closure */
  814. Xextern int mkopt PROTO((int));    /* make a machine optional */
  815. X
  816. X/* make a machine that matches either one of two machines */
  817. Xextern int mkor PROTO((int, int));
  818. X
  819. X/* convert a machine into a positive closure */
  820. Xextern int mkposcl PROTO((int));
  821. X
  822. Xextern int mkrep PROTO((int, int, int));    /* make a replicated machine */
  823. X
  824. X/* create a state with a transition on a given symbol */
  825. Xextern int mkstate PROTO((int));
  826. X
  827. Xextern void new_rule PROTO(());    /* initialize for a new rule */
  828. X
  829. X
  830. X/* from file parse.y */
  831. X
  832. X/* write out a message formatted with one string, pinpointing its location */
  833. Xextern void format_pinpoint_message PROTO((char[], char[]));
  834. X
  835. X/* write out a message, pinpointing its location */
  836. Xextern void pinpoint_message PROTO((char[]));
  837. X
  838. Xextern void synerr PROTO((char []));    /* report a syntax error */
  839. Xextern int yyparse PROTO(());    /* the YACC parser */
  840. X
  841. X
  842. X/* from file scan.l */
  843. X
  844. Xextern int flexscan PROTO(());    /* the Flex-generated scanner for flex */
  845. X
  846. X/* open the given file (if NULL, stdin) for scanning */
  847. Xextern void set_input_file PROTO((char*));
  848. X
  849. Xextern int yywrap PROTO(());    /* wrapup a file in the lexical analyzer */
  850. X
  851. X
  852. X/* from file sym.c */
  853. X
  854. X/* save the text of a character class */
  855. Xextern void cclinstal PROTO ((Char [], int));
  856. X
  857. X/* lookup the number associated with character class */
  858. Xextern int ccllookup PROTO((Char []));
  859. X
  860. Xextern void ndinstal PROTO((char[], Char[]));    /* install a name definition */
  861. Xextern void scinstal PROTO((char[], int));    /* make a start condition */
  862. X
  863. X/* lookup the number associated with a start condition */
  864. Xextern int sclookup PROTO((char[]));
  865. X
  866. X
  867. X/* from file tblcmp.c */
  868. X
  869. X/* build table entries for dfa state */
  870. Xextern void bldtbl PROTO((int[], int, int, int, int));
  871. X
  872. Xextern void cmptmps PROTO(());    /* compress template table entries */
  873. Xextern void inittbl PROTO(());    /* initialize transition tables */
  874. Xextern void mkdeftbl PROTO(());    /* make the default, "jam" table entries */
  875. X
  876. X/* create table entries for a state (or state fragment) which has
  877. X * only one out-transition */
  878. Xextern void mk1tbl PROTO((int, int, int, int));
  879. X
  880. X/* place a state into full speed transition table */
  881. Xextern void place_state PROTO((int*, int, int));
  882. X
  883. X/* save states with only one out-transition to be processed later */
  884. Xextern void stack1 PROTO((int, int, int, int));
  885. X
  886. X
  887. X/* from file yylex.c */
  888. X
  889. Xextern int yylex PROTO(());
  890. X
  891. X
  892. X/* The Unix kernel calls used here */
  893. X
  894. Xextern int read PROTO((int, char*, int));
  895. Xextern int unlink PROTO((char*));
  896. Xextern int write PROTO((int, char*, int));
  897. END_OF_FILE
  898.   if test 29063 -ne `wc -c <'flexdef.h'`; then
  899.     echo shar: \"'flexdef.h'\" unpacked with wrong size!
  900.   fi
  901.   # end of 'flexdef.h'
  902. fi
  903. if test -f 'main.c' -a "${1}" != "-c" ; then 
  904.   echo shar: Will not clobber existing file \"'main.c'\"
  905. else
  906.   echo shar: Extracting \"'main.c'\" \(19459 characters\)
  907.   sed "s/^X//" >'main.c' <<'END_OF_FILE'
  908. X/* flex - tool to generate fast lexical analyzers */
  909. X
  910. X/*-
  911. X * Copyright (c) 1990 The Regents of the University of California.
  912. X * All rights reserved.
  913. X *
  914. X * This code is derived from software contributed to Berkeley by
  915. X * Vern Paxson.
  916. X * 
  917. X * The United States Government has rights in this work pursuant
  918. X * to contract no. DE-AC03-76SF00098 between the United States
  919. X * Department of Energy and the University of California.
  920. X *
  921. X * Redistribution and use in source and binary forms are permitted provided
  922. X * that: (1) source distributions retain this entire copyright notice and
  923. X * comment, and (2) distributions including binaries display the following
  924. X * acknowledgement:  ``This product includes software developed by the
  925. X * University of California, Berkeley and its contributors'' in the
  926. X * documentation or other materials provided with the distribution and in
  927. X * all advertising materials mentioning features or use of this software.
  928. X * Neither the name of the University nor the names of its contributors may
  929. X * be used to endorse or promote products derived from this software without
  930. X * specific prior written permission.
  931. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  932. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  933. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  934. X */
  935. X
  936. X#ifndef lint
  937. Xchar copyright[] =
  938. X"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
  939. X All rights reserved.\n";
  940. X#endif /* not lint */
  941. X
  942. X#ifndef lint
  943. Xstatic char rcsid[] =
  944. X    "@(#) $Header: /usr/fsys/odin/a/vern/flex/RCS/main.c,v 2.9 90/06/27 23:48:24 vern Exp $ (LBL)";
  945. X#endif
  946. X
  947. X
  948. X#include "flexdef.h"
  949. X
  950. Xstatic char flex_version[] = "2.3";
  951. X
  952. X
  953. X/* declare functions that have forward references */
  954. X
  955. Xvoid flexinit PROTO((int, char**));
  956. Xvoid readin PROTO(());
  957. Xvoid set_up_initial_allocations PROTO(());
  958. X
  959. X
  960. X/* these globals are all defined and commented in flexdef.h */
  961. Xint printstats, syntaxerror, eofseen, ddebug, trace, spprdflt;
  962. Xint interactive, caseins, useecs, fulltbl, usemecs;
  963. Xint fullspd, gen_line_dirs, performance_report, backtrack_report, csize;
  964. Xint yymore_used, reject, real_reject, continued_action;
  965. Xint yymore_really_used, reject_really_used;
  966. Xint datapos, dataline, linenum;
  967. XFILE *skelfile = NULL;
  968. Xchar *infilename = NULL;
  969. Xint onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
  970. Xint onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
  971. Xint current_mns, num_rules, current_max_rules, lastnfa;
  972. Xint *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
  973. Xint *accptnum, *assoc_rule, *state_type, *rule_type, *rule_linenum;
  974. Xint current_state_type;
  975. Xint variable_trailing_context_rules;
  976. Xint numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
  977. Xint protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
  978. Xint numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs, tecfwd[CSIZE + 1];
  979. Xint tecbck[CSIZE + 1];
  980. Xint *xlation = (int *) 0;
  981. Xint num_xlations;
  982. Xint lastsc, current_max_scs, *scset, *scbol, *scxclu, *sceof, *actvsc;
  983. Xchar **scname;
  984. Xint current_max_dfa_size, current_max_xpairs;
  985. Xint current_max_template_xpairs, current_max_dfas;
  986. Xint lastdfa, *nxt, *chk, *tnxt;
  987. Xint *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
  988. Xunion dfaacc_union *dfaacc;
  989. Xint *accsiz, *dhash, numas;
  990. Xint numsnpairs, jambase, jamstate;
  991. Xint lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse;
  992. Xint current_max_ccl_tbl_size;
  993. XChar *ccltbl;
  994. Xchar *starttime, *endtime, nmstr[MAXLINE];
  995. Xint sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
  996. Xint tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
  997. Xint num_backtracking, bol_needed;
  998. XFILE *temp_action_file;
  999. XFILE *backtrack_file;
  1000. Xint end_of_buffer_state;
  1001. Xchar *action_file_name = NULL;
  1002. Xchar **input_files;
  1003. Xint num_input_files;
  1004. Xchar *program_name;
  1005. X
  1006. X#ifndef SHORT_FILE_NAMES
  1007. Xstatic char *outfile = "lex.yy.c";
  1008. X#else
  1009. Xstatic char *outfile = "lexyy.c";
  1010. X#endif
  1011. Xstatic int outfile_created = 0;
  1012. Xstatic int use_stdout;
  1013. Xstatic char *skelname = NULL;
  1014. X
  1015. X
  1016. Xint main( argc, argv )
  1017. Xint argc;
  1018. Xchar **argv;
  1019. X
  1020. X    {
  1021. X    flexinit( argc, argv );
  1022. X
  1023. X    readin();
  1024. X
  1025. X    if ( syntaxerror )
  1026. X    flexend( 1 );
  1027. X
  1028. X    if ( yymore_really_used == REALLY_USED )
  1029. X    yymore_used = true;
  1030. X    else if ( yymore_really_used == REALLY_NOT_USED )
  1031. X    yymore_used = false;
  1032. X
  1033. X    if ( reject_really_used == REALLY_USED )
  1034. X    reject = true;
  1035. X    else if ( reject_really_used == REALLY_NOT_USED )
  1036. X    reject = false;
  1037. X
  1038. X    if ( performance_report )
  1039. X    {
  1040. X    if ( interactive )
  1041. X        fprintf( stderr,
  1042. X             "-I (interactive) entails a minor performance penalty\n" );
  1043. X
  1044. X    if ( yymore_used )
  1045. X        fprintf( stderr, "yymore() entails a minor performance penalty\n" );
  1046. X
  1047. X    if ( reject )
  1048. X        fprintf( stderr, "REJECT entails a large performance penalty\n" );
  1049. X
  1050. X    if ( variable_trailing_context_rules )
  1051. X        fprintf( stderr,
  1052. X"Variable trailing context rules entail a large performance penalty\n" );
  1053. X    }
  1054. X
  1055. X    if ( reject )
  1056. X    real_reject = true;
  1057. X
  1058. X    if ( variable_trailing_context_rules )
  1059. X    reject = true;
  1060. X
  1061. X    if ( (fulltbl || fullspd) && reject )
  1062. X    {
  1063. X    if ( real_reject )
  1064. X        flexerror( "REJECT cannot be used with -f or -F" );
  1065. X    else
  1066. X        flexerror(
  1067. X    "variable trailing context rules cannot be used with -f or -F" );
  1068. X    }
  1069. X
  1070. X    ntod();
  1071. X
  1072. X    /* generate the C state transition tables from the DFA */
  1073. X    make_tables();
  1074. X
  1075. X    /* note, flexend does not return.  It exits with its argument as status. */
  1076. X
  1077. X    flexend( 0 );
  1078. X
  1079. X    /*NOTREACHED*/
  1080. X    }
  1081. X
  1082. X
  1083. X/* flexend - terminate flex
  1084. X *
  1085. X * synopsis
  1086. X *    int status;
  1087. X *    flexend( status );
  1088. X *
  1089. X *    status is exit status.
  1090. X *
  1091. X * note
  1092. X *    This routine does not return.
  1093. X */
  1094. X
  1095. Xvoid flexend( status )
  1096. Xint status;
  1097. X
  1098. X    {
  1099. X    int tblsiz;
  1100. X    char *flex_gettime();
  1101. X
  1102. X    if ( skelfile != NULL )
  1103. X    {
  1104. X    if ( ferror( skelfile ) )
  1105. X        flexfatal( "error occurred when writing skeleton file" );
  1106. X
  1107. X    else if ( fclose( skelfile ) )
  1108. X        flexfatal( "error occurred when closing skeleton file" );
  1109. X    }
  1110. X
  1111. X    if ( temp_action_file )
  1112. X    {
  1113. X    if ( ferror( temp_action_file ) )
  1114. X        flexfatal( "error occurred when writing temporary action file" );
  1115. X
  1116. X    else if ( fclose( temp_action_file ) )
  1117. X        flexfatal( "error occurred when closing temporary action file" );
  1118. X
  1119. X    else if ( unlink( action_file_name ) )
  1120. X        flexfatal( "error occurred when deleting temporary action file" );
  1121. X    }
  1122. X
  1123. X    if ( status != 0 && outfile_created )
  1124. X    {
  1125. X    if ( ferror( stdout ) )
  1126. X        flexfatal( "error occurred when writing output file" );
  1127. X
  1128. X    else if ( fclose( stdout ) )
  1129. X        flexfatal( "error occurred when closing output file" );
  1130. X
  1131. X    else if ( unlink( outfile ) )
  1132. X        flexfatal( "error occurred when deleting output file" );
  1133. X    }
  1134. X
  1135. X    if ( backtrack_report && backtrack_file )
  1136. X    {
  1137. X    if ( num_backtracking == 0 )
  1138. X        fprintf( backtrack_file, "No backtracking.\n" );
  1139. X    else if ( fullspd || fulltbl )
  1140. X        fprintf( backtrack_file,
  1141. X             "%d backtracking (non-accepting) states.\n",
  1142. X             num_backtracking );
  1143. X    else
  1144. X        fprintf( backtrack_file, "Compressed tables always backtrack.\n" );
  1145. X
  1146. X    if ( ferror( backtrack_file ) )
  1147. X        flexfatal( "error occurred when writing backtracking file" );
  1148. X
  1149. X    else if ( fclose( backtrack_file ) )
  1150. X        flexfatal( "error occurred when closing backtracking file" );
  1151. X    }
  1152. X
  1153. X    if ( printstats )
  1154. X    {
  1155. X    endtime = flex_gettime();
  1156. X
  1157. X    fprintf( stderr, "%s version %s usage statistics:\n", program_name,
  1158. X         flex_version );
  1159. X    fprintf( stderr, "  started at %s, finished at %s\n",
  1160. X         starttime, endtime );
  1161. X
  1162. X    fprintf( stderr, "  scanner options: -" );
  1163. X
  1164. X    if ( backtrack_report )
  1165. X        putc( 'b', stderr );
  1166. X    if ( ddebug )
  1167. X        putc( 'd', stderr );
  1168. X    if ( interactive )
  1169. X        putc( 'I', stderr );
  1170. X    if ( caseins )
  1171. X        putc( 'i', stderr );
  1172. X    if ( ! gen_line_dirs )
  1173. X        putc( 'L', stderr );
  1174. X    if ( performance_report )
  1175. X        putc( 'p', stderr );
  1176. X    if ( spprdflt )
  1177. X        putc( 's', stderr );
  1178. X    if ( use_stdout )
  1179. X        putc( 't', stderr );
  1180. X    if ( trace )
  1181. X        putc( 'T', stderr );
  1182. X    if ( printstats )
  1183. X        putc( 'v', stderr );    /* always true! */
  1184. X    if ( csize == 256 )
  1185. X        putc( '8', stderr );
  1186. X
  1187. X    fprintf( stderr, " -C" );
  1188. X
  1189. X    if ( fulltbl )
  1190. X        putc( 'f', stderr );
  1191. X    if ( fullspd )
  1192. X        putc( 'F', stderr );
  1193. X    if ( useecs )
  1194. X        putc( 'e', stderr );
  1195. X    if ( usemecs )
  1196. X        putc( 'm', stderr );
  1197. X
  1198. X    if ( strcmp( skelname, DEFAULT_SKELETON_FILE ) )
  1199. X        fprintf( stderr, " -S%s", skelname );
  1200. X
  1201. X    putc( '\n', stderr );
  1202. X
  1203. X    fprintf( stderr, "  %d/%d NFA states\n", lastnfa, current_mns );
  1204. X    fprintf( stderr, "  %d/%d DFA states (%d words)\n", lastdfa,
  1205. X         current_max_dfas, totnst );
  1206. X    fprintf( stderr,
  1207. X         "  %d rules\n", num_rules - 1 /* - 1 for def. rule */ );
  1208. X
  1209. X    if ( num_backtracking == 0 )
  1210. X        fprintf( stderr, "  No backtracking\n" );
  1211. X    else if ( fullspd || fulltbl )
  1212. X        fprintf( stderr, "  %d backtracking (non-accepting) states\n",
  1213. X             num_backtracking );
  1214. X    else
  1215. X        fprintf( stderr, "  compressed tables always backtrack\n" );
  1216. X
  1217. X    if ( bol_needed )
  1218. X        fprintf( stderr, "  Beginning-of-line patterns used\n" );
  1219. X
  1220. X    fprintf( stderr, "  %d/%d start conditions\n", lastsc,
  1221. X         current_max_scs );
  1222. X    fprintf( stderr, "  %d epsilon states, %d double epsilon states\n",
  1223. X         numeps, eps2 );
  1224. X
  1225. X    if ( lastccl == 0 )
  1226. X        fprintf( stderr, "  no character classes\n" );
  1227. X    else
  1228. X        fprintf( stderr,
  1229. X    "  %d/%d character classes needed %d/%d words of storage, %d reused\n",
  1230. X             lastccl, current_maxccls,
  1231. X             cclmap[lastccl] + ccllen[lastccl],
  1232. X             current_max_ccl_tbl_size, cclreuse );
  1233. X
  1234. X    fprintf( stderr, "  %d state/nextstate pairs created\n", numsnpairs );
  1235. X    fprintf( stderr, "  %d/%d unique/duplicate transitions\n",
  1236. X         numuniq, numdup );
  1237. X
  1238. X    if ( fulltbl )
  1239. X        {
  1240. X        tblsiz = lastdfa * numecs;
  1241. X        fprintf( stderr, "  %d table entries\n", tblsiz );
  1242. X        }
  1243. X
  1244. X    else
  1245. X        {
  1246. X        tblsiz = 2 * (lastdfa + numtemps) + 2 * tblend;
  1247. X
  1248. X        fprintf( stderr, "  %d/%d base-def entries created\n",
  1249. X             lastdfa + numtemps, current_max_dfas );
  1250. X        fprintf( stderr, "  %d/%d (peak %d) nxt-chk entries created\n",
  1251. X             tblend, current_max_xpairs, peakpairs );
  1252. X        fprintf( stderr,
  1253. X             "  %d/%d (peak %d) template nxt-chk entries created\n",
  1254. X             numtemps * nummecs, current_max_template_xpairs,
  1255. X             numtemps * numecs );
  1256. X        fprintf( stderr, "  %d empty table entries\n", nummt );
  1257. X        fprintf( stderr, "  %d protos created\n", numprots );
  1258. X        fprintf( stderr, "  %d templates created, %d uses\n",
  1259. X             numtemps, tmpuses );
  1260. X        }
  1261. X
  1262. X    if ( useecs )
  1263. X        {
  1264. X        tblsiz = tblsiz + csize;
  1265. X        fprintf( stderr, "  %d/%d equivalence classes created\n",
  1266. X             numecs, csize );
  1267. X        }
  1268. X
  1269. X    if ( usemecs )
  1270. X        {
  1271. X        tblsiz = tblsiz + numecs;
  1272. X        fprintf( stderr, "  %d/%d meta-equivalence classes created\n",
  1273. X             nummecs, csize );
  1274. X        }
  1275. X
  1276. X    fprintf( stderr, "  %d (%d saved) hash collisions, %d DFAs equal\n",
  1277. X         hshcol, hshsave, dfaeql );
  1278. X    fprintf( stderr, "  %d sets of reallocations needed\n", num_reallocs );
  1279. X    fprintf( stderr, "  %d total table entries needed\n", tblsiz );
  1280. X    }
  1281. X
  1282. X#ifndef VMS
  1283. X    exit( status );
  1284. X#else
  1285. X    exit( status + 1 );
  1286. X#endif
  1287. X    }
  1288. X
  1289. X
  1290. X/* flexinit - initialize flex
  1291. X *
  1292. X * synopsis
  1293. X *    int argc;
  1294. X *    char **argv;
  1295. X *    flexinit( argc, argv );
  1296. X */
  1297. X
  1298. Xvoid flexinit( argc, argv )
  1299. Xint argc;
  1300. Xchar **argv;
  1301. X
  1302. X    {
  1303. X    int i, sawcmpflag;
  1304. X    char *arg, *flex_gettime(), *mktemp();
  1305. X
  1306. X    printstats = syntaxerror = trace = spprdflt = interactive = caseins = false;
  1307. X    backtrack_report = performance_report = ddebug = fulltbl = fullspd = false;
  1308. X    yymore_used = continued_action = reject = false;
  1309. X    yymore_really_used = reject_really_used = false;
  1310. X    gen_line_dirs = usemecs = useecs = true;
  1311. X
  1312. X    sawcmpflag = false;
  1313. X    use_stdout = false;
  1314. X
  1315. X    csize = DEFAULT_CSIZE;
  1316. X
  1317. X    program_name = argv[0];
  1318. X
  1319. X    /* read flags */
  1320. X    for ( --argc, ++argv; argc ; --argc, ++argv )
  1321. X    {
  1322. X    if ( argv[0][0] != '-' || argv[0][1] == '\0' )
  1323. X        break;
  1324. X
  1325. X    arg = argv[0];
  1326. X
  1327. X    for ( i = 1; arg[i] != '\0'; ++i )
  1328. X        switch ( arg[i] )
  1329. X        {
  1330. X        case 'b':
  1331. X            backtrack_report = true;
  1332. X            break;
  1333. X
  1334. X        case 'c':
  1335. X            fprintf( stderr,
  1336. X    "%s: Assuming use of deprecated -c flag is really intended to be -C\n",
  1337. X                 program_name );
  1338. X
  1339. X            /* fall through */
  1340. X
  1341. X        case 'C':
  1342. X            if ( i != 1 )
  1343. X            flexerror( "-C flag must be given separately" );
  1344. X
  1345. X            if ( ! sawcmpflag )
  1346. X            {
  1347. X            useecs = false;
  1348. X            usemecs = false;
  1349. X            fulltbl = false;
  1350. X            sawcmpflag = true;
  1351. X            }
  1352. X
  1353. X            for ( ++i; arg[i] != '\0'; ++i )
  1354. X            switch ( arg[i] )
  1355. X                {
  1356. X                case 'e':
  1357. X                useecs = true;
  1358. X                break;
  1359. X
  1360. X                case 'F':
  1361. X                fullspd = true;
  1362. X                break;
  1363. X
  1364. X                case 'f':
  1365. X                fulltbl = true;
  1366. X                break;
  1367. X
  1368. X                case 'm':
  1369. X                usemecs = true;
  1370. X                break;
  1371. X
  1372. X                default:
  1373. X                lerrif( "unknown -C option '%c'",
  1374. X                    (int) arg[i] );
  1375. X                break;
  1376. X                }
  1377. X
  1378. X            goto get_next_arg;
  1379. X
  1380. X        case 'd':
  1381. X            ddebug = true;
  1382. X            break;
  1383. X
  1384. X        case 'f':
  1385. X            useecs = usemecs = false;
  1386. X            fulltbl = true;
  1387. X            break;
  1388. X
  1389. X        case 'F':
  1390. X            useecs = usemecs = false;
  1391. X            fullspd = true;
  1392. X            break;
  1393. X
  1394. X        case 'I':
  1395. X            interactive = true;
  1396. X            break;
  1397. X
  1398. X        case 'i':
  1399. X            caseins = true;
  1400. X            break;
  1401. X
  1402. X        case 'L':
  1403. X            gen_line_dirs = false;
  1404. X            break;
  1405. X
  1406. X        case 'n':
  1407. X            /* stupid do-nothing deprecated option */
  1408. X            break;
  1409. X
  1410. X        case 'p':
  1411. X            performance_report = true;
  1412. X            break;
  1413. X
  1414. X        case 'S':
  1415. X            if ( i != 1 )
  1416. X            flexerror( "-S flag must be given separately" );
  1417. X
  1418. X            skelname = arg + i + 1;
  1419. X            goto get_next_arg;
  1420. X
  1421. X        case 's':
  1422. X            spprdflt = true;
  1423. X            break;
  1424. X
  1425. X        case 't':
  1426. X            use_stdout = true;
  1427. X            break;
  1428. X
  1429. X        case 'T':
  1430. X            trace = true;
  1431. X            break;
  1432. X
  1433. X        case 'v':
  1434. X            printstats = true;
  1435. X            break;
  1436. X
  1437. X        case '8':
  1438. X            csize = CSIZE;
  1439. X            break;
  1440. X
  1441. X        default:
  1442. X            lerrif( "unknown flag '%c'", (int) arg[i] );
  1443. X            break;
  1444. X        }
  1445. X
  1446. Xget_next_arg: /* used by -C and -S flags in lieu of a "continue 2" control */
  1447. X    ;
  1448. X    }
  1449. X
  1450. X    if ( (fulltbl || fullspd) && usemecs )
  1451. X    flexerror( "full table and -Cm don't make sense together" );
  1452. X
  1453. X    if ( (fulltbl || fullspd) && interactive )
  1454. X    flexerror( "full table and -I are (currently) incompatible" );
  1455. X
  1456. X    if ( fulltbl && fullspd )
  1457. X    flexerror( "full table and -F are mutually exclusive" );
  1458. X
  1459. X    if ( ! skelname )
  1460. X    {
  1461. X    static char skeleton_name_storage[400];
  1462. X
  1463. X    skelname = skeleton_name_storage;
  1464. X    (void) strcpy( skelname, DEFAULT_SKELETON_FILE );
  1465. X    }
  1466. X
  1467. X    if ( ! use_stdout )
  1468. X    {
  1469. X    FILE *prev_stdout = freopen( outfile, "w", stdout );
  1470. X
  1471. X    if ( prev_stdout == NULL )
  1472. X        lerrsf( "could not create %s", outfile );
  1473. X
  1474. X    outfile_created = 1;
  1475. X    }
  1476. X
  1477. X    num_input_files = argc;
  1478. X    input_files = argv;
  1479. X    set_input_file( num_input_files > 0 ? input_files[0] : NULL );
  1480. X
  1481. X    if ( backtrack_report )
  1482. X    {
  1483. X#ifndef SHORT_FILE_NAMES
  1484. X    backtrack_file = fopen( "lex.backtrack", "w" );
  1485. X#else
  1486. X    backtrack_file = fopen( "lex.bck", "w" );
  1487. X#endif
  1488. X
  1489. X    if ( backtrack_file == NULL )
  1490. X        flexerror( "could not create lex.backtrack" );
  1491. X    }
  1492. X
  1493. X    else
  1494. X    backtrack_file = NULL;
  1495. X
  1496. X
  1497. X    lastccl = 0;
  1498. X    lastsc = 0;
  1499. X
  1500. X    /* initialize the statistics */
  1501. X    starttime = flex_gettime();
  1502. X
  1503. X    if ( (skelfile = fopen( skelname, "r" )) == NULL )
  1504. X    lerrsf( "can't open skeleton file %s", skelname );
  1505. X
  1506. X#ifdef SYS_V
  1507. X    action_file_name = tmpnam( NULL );
  1508. X#endif
  1509. X
  1510. X    if ( action_file_name == NULL )
  1511. X    {
  1512. X    static char temp_action_file_name[32];
  1513. X
  1514. X#ifndef SHORT_FILE_NAMES
  1515. X    (void) strcpy( temp_action_file_name, "/tmp/flexXXXXXX" );
  1516. X#else
  1517. X    (void) strcpy( temp_action_file_name, "flexXXXXXX.tmp" );
  1518. X#endif
  1519. X    (void) mktemp( temp_action_file_name );
  1520. X
  1521. X    action_file_name = temp_action_file_name;
  1522. X    }
  1523. X
  1524. X    if ( (temp_action_file = fopen( action_file_name, "w" )) == NULL )
  1525. X    lerrsf( "can't open temporary action file %s", action_file_name );
  1526. X
  1527. X    lastdfa = lastnfa = num_rules = numas = numsnpairs = tmpuses = 0;
  1528. X    numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0;
  1529. X    numuniq = numdup = hshsave = eofseen = datapos = dataline = 0;
  1530. X    num_backtracking = onesp = numprots = 0;
  1531. X    variable_trailing_context_rules = bol_needed = false;
  1532. X
  1533. X    linenum = sectnum = 1;
  1534. X    firstprot = NIL;
  1535. X
  1536. X    /* used in mkprot() so that the first proto goes in slot 1
  1537. X     * of the proto queue
  1538. X     */
  1539. X    lastprot = 1;
  1540. X
  1541. X    if ( useecs )
  1542. X    { /* set up doubly-linked equivalence classes */
  1543. X    /* We loop all the way up to csize, since ecgroup[csize] is the
  1544. X     * position used for NUL characters
  1545. X     */
  1546. X    ecgroup[1] = NIL;
  1547. X
  1548. X    for ( i = 2; i <= csize; ++i )
  1549. X        {
  1550. X        ecgroup[i] = i - 1;
  1551. X        nextecm[i - 1] = i;
  1552. X        }
  1553. X
  1554. X    nextecm[csize] = NIL;
  1555. X    }
  1556. X
  1557. X    else
  1558. X    { /* put everything in its own equivalence class */
  1559. X    for ( i = 1; i <= csize; ++i )
  1560. X        {
  1561. X        ecgroup[i] = i;
  1562. X        nextecm[i] = BAD_SUBSCRIPT;    /* to catch errors */
  1563. X        }
  1564. X    }
  1565. X
  1566. X    set_up_initial_allocations();
  1567. X    }
  1568. X
  1569. X
  1570. X/* readin - read in the rules section of the input file(s)
  1571. X *
  1572. X * synopsis
  1573. X *    readin();
  1574. X */
  1575. X
  1576. Xvoid readin()
  1577. X
  1578. X    {
  1579. X    skelout();
  1580. X
  1581. X    if ( ddebug )
  1582. X    puts( "#define FLEX_DEBUG" );
  1583. X
  1584. X    if ( csize == 256 )
  1585. X    puts( "#define YY_CHAR unsigned char" );
  1586. X    else
  1587. X    puts( "#define YY_CHAR char" );
  1588. X
  1589. X    line_directive_out( stdout );
  1590. X
  1591. X    if ( yyparse() )
  1592. X    {
  1593. X    pinpoint_message( "fatal parse error" );
  1594. X    flexend( 1 );
  1595. X    }
  1596. X
  1597. X    if ( xlation )
  1598. X    {
  1599. X    numecs = ecs_from_xlation( ecgroup );
  1600. X    useecs = true;
  1601. X    }
  1602. X
  1603. X    else if ( useecs )
  1604. X    numecs = cre8ecs( nextecm, ecgroup, csize );
  1605. X
  1606. X    else
  1607. X    numecs = csize;
  1608. X
  1609. X    /* now map the equivalence class for NUL to its expected place */
  1610. X    ecgroup[0] = ecgroup[csize];
  1611. X    NUL_ec = abs( ecgroup[0] );
  1612. X
  1613. X    if ( useecs )
  1614. X    ccl2ecl();
  1615. X    }
  1616. X
  1617. X
  1618. X
  1619. X/* set_up_initial_allocations - allocate memory for internal tables */
  1620. X
  1621. Xvoid set_up_initial_allocations()
  1622. X
  1623. X    {
  1624. X    current_mns = INITIAL_MNS;
  1625. X    firstst = allocate_integer_array( current_mns );
  1626. X    lastst = allocate_integer_array( current_mns );
  1627. X    finalst = allocate_integer_array( current_mns );
  1628. X    transchar = allocate_integer_array( current_mns );
  1629. X    trans1 = allocate_integer_array( current_mns );
  1630. X    trans2 = allocate_integer_array( current_mns );
  1631. X    accptnum = allocate_integer_array( current_mns );
  1632. X    assoc_rule = allocate_integer_array( current_mns );
  1633. X    state_type = allocate_integer_array( current_mns );
  1634. X
  1635. X    current_max_rules = INITIAL_MAX_RULES;
  1636. X    rule_type = allocate_integer_array( current_max_rules );
  1637. X    rule_linenum = allocate_integer_array( current_max_rules );
  1638. X
  1639. X    current_max_scs = INITIAL_MAX_SCS;
  1640. X    scset = allocate_integer_array( current_max_scs );
  1641. X    scbol = allocate_integer_array( current_max_scs );
  1642. X    scxclu = allocate_integer_array( current_max_scs );
  1643. X    sceof = allocate_integer_array( current_max_scs );
  1644. X    scname = allocate_char_ptr_array( current_max_scs );
  1645. X    actvsc = allocate_integer_array( current_max_scs );
  1646. X
  1647. X    current_maxccls = INITIAL_MAX_CCLS;
  1648. X    cclmap = allocate_integer_array( current_maxccls );
  1649. X    ccllen = allocate_integer_array( current_maxccls );
  1650. X    cclng = allocate_integer_array( current_maxccls );
  1651. X
  1652. X    current_max_ccl_tbl_size = INITIAL_MAX_CCL_TBL_SIZE;
  1653. X    ccltbl = allocate_character_array( current_max_ccl_tbl_size );
  1654. X
  1655. X    current_max_dfa_size = INITIAL_MAX_DFA_SIZE;
  1656. X
  1657. X    current_max_xpairs = INITIAL_MAX_XPAIRS;
  1658. X    nxt = allocate_integer_array( current_max_xpairs );
  1659. X    chk = allocate_integer_array( current_max_xpairs );
  1660. X
  1661. X    current_max_template_xpairs = INITIAL_MAX_TEMPLATE_XPAIRS;
  1662. X    tnxt = allocate_integer_array( current_max_template_xpairs );
  1663. X
  1664. X    current_max_dfas = INITIAL_MAX_DFAS;
  1665. X    base = allocate_integer_array( current_max_dfas );
  1666. X    def = allocate_integer_array( current_max_dfas );
  1667. X    dfasiz = allocate_integer_array( current_max_dfas );
  1668. X    accsiz = allocate_integer_array( current_max_dfas );
  1669. X    dhash = allocate_integer_array( current_max_dfas );
  1670. X    dss = allocate_int_ptr_array( current_max_dfas );
  1671. X    dfaacc = allocate_dfaacc_union( current_max_dfas );
  1672. X
  1673. X    nultrans = (int *) 0;
  1674. X    }
  1675. END_OF_FILE
  1676.   if test 19459 -ne `wc -c <'main.c'`; then
  1677.     echo shar: \"'main.c'\" unpacked with wrong size!
  1678.   fi
  1679.   # end of 'main.c'
  1680. fi
  1681. echo shar: End of archive 5 \(of 10\).
  1682. cp /dev/null ark5isdone
  1683. MISSING=""
  1684. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  1685.     if test ! -f ark${I}isdone ; then
  1686.     MISSING="${MISSING} ${I}"
  1687.     fi
  1688. done
  1689. if test "${MISSING}" = "" ; then
  1690.     echo You have unpacked all 10 archives.
  1691.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1692. else
  1693.     echo You still must unpack the following archives:
  1694.     echo "        " ${MISSING}
  1695. fi
  1696. exit 0
  1697. exit 0 # Just in case...
  1698.